import 'package:e_book/http/spider/spider_api.dart';
import 'package:e_book/model/book.dart';
import 'package:flutter/material.dart';

class DubanStoreViewModel extends ChangeNotifier{
  List<Book>?_expressBooks; // 新书速递
  List<Book>?_weekBooks; // 一周热门
  List<Book>?_top250Books; // top250
  
  List<Book>?get expressBooks => _expressBooks;
  List<Book>?get weekBooks => _weekBooks;
  List<Book>?get top250Books => _top250Books;

  set expressBooks(List<Book>?expressBooks){
    _expressBooks = expressBooks;
    notifyListeners();
  }
  set weekBooks(List<Book>?weekBooks){
    _weekBooks = weekBooks;
    notifyListeners();
  }
  set top250Books(List<Book>?top250Books){
    _top250Books = top250Books;
    notifyListeners();
  }

  Future getDoubanStoreData() async {
    expressBooks = await SpiderApi.instance().fetchExoressBooks();
    // 剩余数据没有JSON数据  通过回调方式统一获取
    SpiderApi.instance().fetchDoubanStoreData(
      weekBooksCallback:(List<Book> values)=>weekBooks = values,
      top250Callback:(List<Book> values)=>top250Books = values,
    );
  }
}